Python Installation


Many of you will not have Python 3.7 already installed on your computers. Conda is an easy way to manage many different environments, each with its own Python versions and dependencies. This allows us to avoid conflicts between our preferred Python version and that of other classes. We’ll walk through how to set up and use a conda environment.

Prerequisite: Anaconda. If you don’t have, install it through the link.

Creating a Conda Environment

The command for creating a conda environment with Python 3.7 is:

conda create --name <env-name> python=3.7

For us, we decide to name our environment cs181, so we run the following command, and press y to confirm installing any missing packages.

[cs181-ta@nova ~/python_basics]$ conda create --name cs181 python=3.7.5

Entering the Environment

To enter the conda environment that we just created, do the following. Note that the Python version within the environment is 3.7, just what we want.

[cs181-ta@nova ~/python_basics]$ source activate cs181
(cs181) [cs181-ta@nova ~/python_basics]$ python -V
Python 3.7.5 :: Anaconda, Inc.

Note: the tag (<env-name>) shows you the name of the conda environment that is active. In our case, we have (cs181), as what we’d expect.

Leaving the Environment

Leaving the environment is just as easy.

(cs181) [cs181-ta@nova ~/python_basics]$ source deactivate
[cs181-ta@nova ~/python_basics]$ python -V
Python 3.5.2 :: Anaconda custom (x86_64)

Our python version has now returned to whatever the system default is!